package com.infore.exchange.main.dao;

import com.infore.common.model.entity.exchange.TDatabaseInfo;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 数据库信息表 Mapper 接口
 * </p>
 *
 * @author lijh
 * @since 2023-02-07
 */
@Mapper
@Component
public interface TDatabaseInfoMapper extends BaseMapper<TDatabaseInfo> {


//    MYSQL
/*    @Select("SELECT sum(table_rows) as totalRows, ROUND(sum(data_length+index_length)/1024/1024/1024,2) as totalGB " +
            "FROM information_schema.TABLES where TABLE_SCHEMA=#{schema}")*/
//    达梦（DM）
/*    @Select("select totalRows,totalGB from (\n" +
            "select owner,ROUND(sum(t.bytes)/1024.0/1024.0/1024.0,2) as totalGB\n" +
            "from dba_segments t\n" +
            "where 1=1\n" +
            "and t.segment_type in ('TABLE','INDEX')\n" +
            "and owner=#{schema}\n" +
            "group by OWNER\n" +
            ") t1\n" +
            "left join (\n" +
            "SELECT owner,sum(TABLE_ROWCOUNT(OWNER,TABLE_NAME)) as totalRows\n" +
            "FROM all_tables  where  owner = #{schema}\n" +
            "group by owner\n" +
            ")t2 on t1.owner=t2.owner")*/
    Map<String,Object> queryDatabaseRowNumAndTotalSpace(@Param("driverAlias")String driverAlias,@Param("schema")  String schema);


//    MYSQL
//    @Select("SELECT table_schema as schema_name,count(1)  as schema_tabes  FROM information_schema.TABLES WHERE table_schema LIKE 'db_%' GROUP BY table_schema")
//   达梦（DM）
//    @Select("SELECT owner as schema_name,count(1)  as schema_tabes  FROM all_tables WHERE owner LIKE 'db_%' GROUP BY owner")
    List<Map<String,Object>> querySchematabes(@Param("driverAlias")String driverAlias);








}
